format
Uses this text as a format string and returns the text obtained by substituting the specified arguments.
Supports many of the format specifiers found in other programming languages, including:
%s
fortext
%d
forinteger
s andbig_integer
s in decimal (base 10) representation%o
forinteger
s andbig_integer
s in octal (base 8) representation%x
forinteger
s andbig_integer
s in hexadecimal (base 16) representation%f
fordecimal
(supports precision, e.g.%.2f
for two decimal places)%b
forboolean
s (output in lower-case, i.e.true
andfalse
)%B
forboolean
s (output in upper-case, i.e.TRUE
andFALSE
)
Examples:
'My integer is %d.'.format(123)
returns'My integer is 123.'
.'See you...%10s.'.format('later')
returns'See you... later.'
.'Earnings: daily=%f, weekly=%f, monthly=%f.'.format(312.45, 534.78, 2199.67)
returns'Earnings: daily=312.450000, weekly=534.780000, monthly=2199.670000.'
.''%d %o %x'.format(14, 14, 14)'
returns'14 16 e'
.
If any format specifier is incompatible with the type of its corresponding argument, or if there are more specifiers requiring substitution than there are arguments, all format specifiers are left unsubstituted in the output text.
All format specifiers are also left unsubstituted in the output text when any argument is null
, except when it matches the specifier is %s
, in which case the text 'null'
is substituted (assuming the other arguments and specifiers are correctly matched).
If there are more arguments than format specifiers, the extra arguments are ignored, but matched arguments are still substituted (assuming they match correctly).
Return
formatted text
Since
0.6.0
Parameters
Arguments referenced by the format specifiers in this format string. The number of arguments is variable and may be zero.